auto.waitFor()
console.show();
var tools=new Tools()
var live=new Live()

// 获取设备屏幕的宽度和高度
var screenWidth = context.getResources().getDisplayMetrics().widthPixels;
var screenHeight = context.getResources().getDisplayMetrics().heightPixels;
console.log(`w:${screenWidth} h:${screenHeight}`)

var appName = "抖音";
launchApp(appName);
sleep(3000);

live.fans("佟海洋");





// execTask();
// function execTask() {
   
//     while(true) {
//     tools.slide()
   
//     console.log("执行滑动")
//     sleep(random(5000,12000));
//     }
// }

function Live(){

    var _tools=new Tools();

    this.fans=function(name){

        _tools.click(949,117,1045,213)
        sleep(random(1500,2500))

        var chatBox = id("et_search_kw").findOne();
	    chatBox.setText(name);
        sleep(random(1000,2000))
        _tools.click(894,99,1080,231) //搜索
        sleep(random(2000, 3000));
        click(567, 1212)
    }

}

function Tools(){

    var me=this

    this.number=1
    
    //随机点击坐标指定范围
    this.click=function(x1,y1,x2,y2){
        var _x=random(x1-5,x2-5)
        var _y=random(y1-5,y2-5)
        console.log(`x:${_x},y:${_y}`)
        click(_x,_y);
    }

    //滑动屏幕 随机
    this.slide=function(){

        var x1 = random(500, 600)
	    var x2 = random(500, 600)
        var y1 = random(1400,1500)
	    var y2 = random(450, 550)
	
	   swipe(x1,y1, x2, y2, random(450, 600))
       console.log(x1, y1, x2, y2);
    }

    this.add=function(){
        me.number++
    }

    this.log=function(){
        me.add()
        console.log(me.number)
    }

    this.func=function(){
        me.log();
    }
}


function getCurrentTime() {
    const now = new Date();
    const minutes = String(now.getMinutes()).padStart(2, '0');
    const seconds = String(now.getSeconds()).padStart(2, '0');
    return `${minutes}:${seconds}`;
}
function clickBtn(btnText,waitingDelay){//传入一个按钮，确保点击了该按钮（搭配findOne，可能传入null或按钮）
    var btn = text(btnText).clickable(true).findOne(waitingDelay);//在给定时间内持续寻找，直到找到
    if(!btn)return false;//未在给定时间内找到按钮
    while(!btn.click());//不断点击按钮直到成功，因此之前要确保按钮是可点击的
    return true;
}
function clickByCoord(btnText,waitingDelay){//控件本身无法点击，转而获取其坐标并模拟点击动作
	var btn = text(btnText).findOne(waitingDelay);//这里处理的是无法点击的控件
    if(!btn)return false;
    var coord= btn.bounds();
    while(!click(coord.centerX(), coord.centerY()));//click(x,y)
    return true;
}



